package com.appspot.niehonglei.action;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.appspot.niehonglei.dao.PMF;
import com.appspot.niehonglei.jdo.Common;

/**
 * 载入Common,并返回编辑页面
 * 
 * @author nehnre
 * 
 */
public class EditCommon implements ActionInterface {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		try {
			String id = request.getParameter("id");
			String type = "0";
			if (id != null && !"".equals(id.trim())) {
				id = id.trim();
				PersistenceManager pm = PMF.get().getPersistenceManager();
				Common common = pm.getObjectById(Common.class,Long.valueOf(id));
				type = common.getType() + "";
				pm.close();
				request.getSession().setAttribute("editCommon", common);
			}
			response.sendRedirect("/common?type=" + type);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
